package ai.assist.common.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel
@Data
public class ResponsePage<T> extends BaseRequest {

    @ApiModelProperty(value = "第几页", required = true)
    private int pageIndex = 1;

    @ApiModelProperty(value = "每页大小", required = true)
    private int pageSize = 10;

    @ApiModelProperty(value = "总行数", required = true)
    private int rowTotal;

    @ApiModelProperty(value = "总共多少页", required = true, hidden = true)
    private int pageTotal = 0;

    @ApiModelProperty(value = "分页对象数据", required = true)
    private T data;

    public int getPageTotal() {
        if (pageTotal > 0) {
            return pageTotal;
        }
        return rowTotal > 0 ? rowTotal % pageSize > 0 ? rowTotal / pageSize + 1 : rowTotal / pageSize : 0;
    }

    @Override
    public String toString() {
        return "ResponsePage{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", rowTotal=" + rowTotal +
                ", pageTotal=" + pageTotal +
                ", data=" + data +
                '}';
    }
}
